import axios from "axios";

axios.defaults.baseURL = 'http://127.0.0.1:3001'

const fun = {
    examlogin: async(name, card, tid) => {
        const {data: {code, sid}} = await axios.post('/zxr/examlogin', {name, card, tid})
        if(code === 201){
            return {state: true, sid}
        }else{
            return {state: false}
        }
    },
    codelogin: async(name, password) => {
        const {data: {code, uid, uname}} = await axios.post('/zxr/back_login', {name, password})
        if(code === 201){
            return {state: true, uid, uname}
        }else{
            return {state: false}
        }
    },
    sendcode: async(phone, content) => {
        const {data: {code, mess}} = await axios.post('/zxr/send_code', {phone, content})
        if(code === 200){
            return {state: true, mess}
        }else{
            return {state: false, mess}
        }
    },
    messaglogin: async(phone) => {
        const {data: {code, uid, uname}} = await axios.post('/zxr/mess_login', {phone})
        if(code === 201){
            return {state: true, uid, uname}
        }else{
            return {state: false}
        }
    },
    resetsend: async(phone, content) => {
        const {data: {code, mess}} = await axios.post('/zxr/reset_send', {phone, content})
        if(code === 200){
            return {state: true, mess}
        }else{
            return {state: false, mess}
        }
    },
    reset: async(phone, password) => {
        const {data: {code, mess}} = await axios.post('/zxr/resetcode', {phone, password})
        if(code === 201){
            return {state: true, mess}
        }else{
            return {state: false, mess}
        }
    },
    getlist: async(uid) => {
        const {data: {code, list}} = await axios.get(`/zxr/get_home?uid=${uid}`)
        if(code === 200){
            return {state: true, list}
        }else{
            return {state: false}
        }
    },
    getdata: async() => {
        const {data: {code, question, paper, clazz, academy, stage,role}} = await axios.get('/zxr/get_data',{params:{uid:sessionStorage.getItem('uid')}})
        if(code === 200){
            return {state: true, question, paper, clazz, academy, stage,role}
        }else{
            return {state: false}
        }
    },
    chartsdata: async(classid) => {
        const {data: {code, namelist, testname, series1}} = await axios.post('/zxr/chartsdata', {classid})
        if(code === 200){
            return {state: true, namelist, testname, series1}
        }else{
            return {state: false}
        }
    },
    checkrole: async(uid) => {
        const {data: {code, urole}} = await axios.post('/zxr/ckrole', {uid})
        if(code === 200){
            return {state: true, urole}
        }else{
            return {state: false}
        }
    }
}

export default fun